package org.halk.controller;

import org.halk.annotation.Lock;
import org.halk.aspect.LockRedisServiceImpl;
import org.halk.entity.UserInfo;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Set;

@RestController
@RequestMapping("/test")
public class TestController {

    @Resource
    private StringRedisTemplate stringRedisTemplate;

    @GetMapping("/available")
    public String test() {

        this.stringRedisTemplate.opsForValue().set("o", "1");

        String o = this.stringRedisTemplate.opsForValue().get("o");
        System.out.println(o);

        Set<String> keys = this.stringRedisTemplate.keys("*");
        keys.forEach(System.out::println);

        return "hello";
    }

    @PostMapping("/aop")
    @Lock(keyType = Lock.KeyType.PARAMETER, paramOrder = 0, expireTime = 6000, waitTime = 3000, methodName = "getAddress")
    public String testAop(@RequestBody UserInfo name) {

        Set<String> keys = this.stringRedisTemplate.keys("*");
        keys.forEach(System.out::println);

        return "hello";
    }
}
